
        package lab01;

public class Test05 {
    public static void main(String[] args) {
        int sum = 0;
        printFor(sum);
        printWhile(sum);
        printDowhile(sum);
    }

    public static void printFor(int sum) {
        for (int i = 1; i <= 1000; i++) {
            sum += i;
        }
        System.out.println("用for语句求1到1000的和:");
        System.out.println("sum=" + sum);
    }

    public static void printWhile(int sum) {
        int i=1;
        while(i<=1000){
            sum +=i;
            i++;
        }
        System.out.println("用while语句求1到1000的和：");
        System.out.println("sum="+sum);
    }

    public static void printDowhile(int sum) {
        int i=1;
        do{
            sum +=i;
            i++;
        }
        while (i<=1000);
        System.out.println("用dowhile语句求1到1000的和：");
        System.out.println("sum="+sum);
    }
}
